import java.util.Stack;

public class Leetcode1021 {
    char left = '(';
    char right = ')';

    public static void main(String[] args) {
        System.out.println(removeOuterParentheses("(()())(())"));
    }

    public static String removeOuterParentheses(String s) {
        StringBuilder builder = new StringBuilder();
        char[] k = s.toCharArray();
        int leftNumber = 0;
        for (char c : k) {
            if (leftNumber == 0) {
                leftNumber++;
                continue;
            }

            if ('(' == c) {
                leftNumber++;
            } else {
                leftNumber--;
            }

            if (leftNumber != 0) {
                builder.append(c);
            }
        }

        return builder.toString();
    }
}
